﻿@{
    ViewBag.Title = "Edit Advertisement";
}
<h2>
    EditAdvertisement</h2>
<link rel="stylesheet" href="@Url.Content("~/Content/css/jquery-ui.css")"/>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui.js")"></script>
<script type="text/javascript">
    $(function () {
        $("#accordion").accordion({
            fillSpace: true,
            autoHeight: true,
            navigation: false,
            collapsible: true
        });
    });
</script>
<script type="text/javascript">
    function updateImg_onclick(id) {
        $('#imgidd').val(id);
    }
</script>
<script type="text/javascript">
    $(document).ready(function(){
$("#insertForm").validate({

rules: {
    password: {
        required: true,
        minlength: 8,
        maxlength: 15,
    }
},
messages: {
    password: {
        required: "Can't be blank.",
        minlength: jQuery.format("You need to use at least {0} characters."),
        maxlength: "Over {0} characters."
    }
}

});
});
</script>
@using SAD_SiS.Models
@model List<Advertisement>
<div id="accordion">
    <h3>
        List image</h3>
    <div>
        <table class="table table-bordered table-hover" width="100%">
            <tr>
                <th>
                    ID
                </th>
                <th>
                    Image
                </th>
                <th>
                    Link
                </th>
                <th>
                </th>
            </tr>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @item.AdImgID
                    </td>
                    <td>
                        <img src="@Url.Content("~/Content/sliderDemoImg/" + @item.ImgName)" alt="Alternate Text" style="width:200px" />
                    </td>
                    <td>
                        @item.Link
                    </td>
                    <td>
                        @if (item.Active == true)
                        {
                            <a class="btn btn-info" href="@Url.Action("AdverInActive", new { imgID = item.AdImgID })">
                                Inactive</a>
                            <a class="btn btn-info" href="@Url.Action("UpdateImgAd", "Advertisement", new { imgID = item.AdImgID })" data-toggle="modal" data-target="#addImgModal" onclick="javascript:updateImg_onclick(@item.AdImgID)">
                                Update</a>
                        }
                        else
                        {
                            <a class="btn btn-info" href="@Url.Action("AdverActive", new { imgID = item.AdImgID })">
                                Active</a>
                            <a class="btn btn-info" href="@Url.Action("UpdateImgAd", "Advertisement", new { imgID = item.AdImgID })" data-toggle="modal" data-target="#addImgModal" onclick="javascript:updateImg_onclick(@item.AdImgID)">
                                Update</a>
                        }
                    </td>
                </tr>
            }
        </table>
    </div>
    <h3>
        Insert new image</h3>
    <div>
        @using (Html.BeginForm("InsertNewImg", "Advertisement", FormMethod.Post, new { enctype = "multipart/form-data" }) )
        {
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td>
                        Link:
                    </td>
                    <td>
                        <input style="width: 300px" type="text" name="newAdlink" value="" />
                    </td>
                </tr>
                <tr>
                    <td>
                        Image:
                    </td>
                    <td>
                        <input type="file" name="file" />
                        <input class="btn btn-primary" type="submit" name="save" value="Save" />
                    </td>
                </tr>
            </table>
        }
    </div>
</div>
<!-- Hidden Login Div -->
<div class="modal hide" id="addImgModal">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" id="btnClose" aria-hidden="true">
            ✕</button>
        <h3>
            Update iamge</h3>
    </div>
    <div class="modal-body" style="text-align: center;">
        @using (Html.BeginForm("UpdateImgAd", "Advertisement", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td>
                        Link:
                    </td>
                    <td>
                        <input style="width: 300px" type="text" name="updateAdlink" value="" />
                    </td>
                </tr>
                <tr>
                    <td>
                        Image:
                    </td>
                    <td>
                        <input type="file" name="fileupdate" />
                        <input type="hidden" id="imgidd" name="imgidd" value="" />
                        <input class="btn btn-primary" type="submit" name="save" value="Save" />
                    </td>
                </tr>
            </table>
        }
    </div>
</div>
